<html>
    <!-- Copyright 2010  Jacob Brunson  (email : gdocsuploader.gpl.license@jacobbrunson.com )

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    -->
<head> 
    <title>Google Docs Authentication</title>
    <link rel="stylesheet" type="text/css" href="../../styles.css" />
    <script src="../prototype/prototype.js" type="text/javascript"></script>
    <script type="text/javascript" src="../air/AIRAliases.js"></script>
    <script type="text/javascript" src="auth.js"></script>
    <script type="text/javascript"> 

    var auth_obj = new GoogleAuth();

    var captchamode = false;

    function loginCallback(b)
    {
        air.trace("Quick test of login complete with result", b);
        if (b) {
            closeWindow();
        } else {
            document.getElementById('errorMessage').innerHTML = "<div align='center'>"+auth_obj.errormsg+"</div>";
            if (auth_obj.captchatoken != "") {
                captchamode = true;
                air.trace("captchatoken is set", auth_obj.captchatoken, auth_obj.captchaurl);
                document.getElementById('errorMessage').innerHTML += "<div align='center'><img src='"+auth_obj.captchaurl+"'/></div>";
                document.getElementById('errorMessage').innerHTML += "<table><tr><td align='right'>Captcha Word:</td>"
                         + "<td><input type='text' id='captcha' name='captcha'/></td></tr></table></div>";
            }
            document.getElementById('loginbutton').value = "Log In";
        }
    }


    function doSignIn()
    {
        document.getElementById('loginbutton').value = "Logging in...";

        email = document.getElementById( 'email' ).value;
        password = document.getElementById( 'password').value;  
        
        air.trace("Saved data into encrypted local store", email);
        auth_obj.setCredentials(email, password); 
        if (document.getElementById('captcha')) {
            air.trace("Detected captcha response", document.getElementById('captcha').value);
            auth_obj.captcharesponse = document.getElementById('captcha').value;
        }
	    
        auth_obj.loggedincallback = loginCallback;
	    auth_obj.googleLogin();

        return false;
    }
        
    function closeWindow()
    {
        window.close();
        window.nativeWindow.close();
    }
    </script> 
</head>
<body onload="air.trace('onload');" onunload="air.trace('onunload');"> 
    <h4>Please Provide Your Google Credentials</h4>
    <form name="loginform" onsubmit="doSignIn(); return false;">
	<table>
	    <tr><td align="right">Google Login:</td><td><input type="text" id="email" name="email"/></td></tr>
	    <tr><td align="right">Password:</td><td><input type="password" id="password" name="password"/></td></tr>
	</table>
	<div id="errorMessage"></div>
        <input type="submit" onclick="" value="Login" id="loginbutton" name="loginbutton"/>
    </form>
</body> 
</html>